//
//  YQNoDataView.m
//  NewRetail
//
//  Created by yuqin on 2019/6/23.
//  Copyright © 2019年 yuqin. All rights reserved.
//

#import "YQNoDataView.h"

@implementation YQNoDataView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self setupView];
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.noDataImg];
    [self addSubview:self.describeLab];
    [self addSubview:self.createBtn];
    
    [self.noDataImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(FIT(40), FIT(40)));
    }];
    
    CGFloat label_W = (ScreenWidth-FIT(36))/2.0;
    
    [self.describeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(self.noDataImg.mas_bottom).mas_equalTo(FIT(10));
        make.size.mas_equalTo(CGSizeMake(label_W+FIT(20), 21));
    }];
    
    [self.createBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.describeLab.mas_right).mas_equalTo(0);
        make.top.equalTo(self.noDataImg.mas_bottom).mas_equalTo(FIT(10));
        make.size.mas_equalTo(CGSizeMake(label_W-FIT(20), 21));
    }];
}

- (UIImageView *)noDataImg {
    if (!_noDataImg) {
        _noDataImg = [YQViewFactory imageViewWithImage:YQ_IMAGE(@"scanning")];
    }
    return _noDataImg;
}

- (UILabel *)describeLab {
    if (!_describeLab) {
        _describeLab = [YQViewFactory labelWithTextColor:MainGrayColor textAlignment:NSTextAlignmentRight fontSize:kLittleFont userBold:NO];
    }
    return _describeLab;
}

- (UIButton *)createBtn {
    if (!_createBtn) {
        _createBtn = [YQViewFactory buttonWithTitle:@"现在创建" titleColor:MainBlueColor fontSize:kLittleFont userBold:NO target:self sel:@selector(createAction)];
        _createBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _createBtn;
}

- (void)createAction {
    if (self.PushBlock) {
        self.PushBlock();
    }
}

- (void)showNoDataView {
    [self setHidden:NO];
}

- (void)hideNoDataView {
    [self setHidden:YES];
}

@end
